﻿using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Records;
using Orchard.ContentManagement.Utilities;

namespace LazyFieldDemo.Models {
    public class CustomerPart : ContentPart<CustomerPartRecord>, ITitleAspect {

        internal LazyField<AddressPart> ShippingAddressField = new LazyField<AddressPart>();
        internal LazyField<AddressPart> BillingAddressField = new LazyField<AddressPart>();

        public string FirstName {
            get { return Record.FirstName; }
            set { Record.FirstName = value; }
        }

        public string LastName {
            get { return Record.LastName; }
            set { Record.LastName = value; }
        }

        public AddressPart ShippingAddress {
            get { return ShippingAddressField.Value; }
            set { ShippingAddressField.Value = value; }
        }

        public AddressPart BillingAddress {
            get { return BillingAddressField.Value; }
            set { BillingAddressField.Value = value; }
        }

        public string Title {
            get { return string.Format("{0} {1}", FirstName, LastName); }
        }
    }

    public class CustomerPartRecord : ContentPartRecord {
        public virtual string FirstName { get; set; }
        public virtual string LastName { get; set; }
        public virtual int? ShippingAddressId { get; set; }
        public virtual int? BillingAddressId { get; set; }
    }
}